1144E - Median String - CodeForces Solution


bitmasks math number theory strings *1900

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h> 

#define LL long long int

using namespace std;



const int MOD=1e9+7;

const int N=2e5+5;



char s[N],t[N];

char a[N];

int temp1[N],temp2[N];

int main()

{

	int k;

	cin>>k;

	scanf("%s",s);

	scanf("%s",t);

	

	int c=0;

	for(int i=k-1;i>=0;i--)

	{

		int tmpt=t[i]-'a'-c,tmps=s[i]-'a';

		if(tmpt<tmps)c=1;

		else c=0;

		temp1[i]=(tmpt+c*26-tmps);

		//cout<<tmpt<<' '<<tmps<<' '<<tmpa<<endl;

	}

	c=0;

	for(int i=0;i<k;i++)

	{

		int tmp=temp1[i]+c*26;

		if(tmp%2==1)c=1;

		else c=0;

		

		temp2[i]=(tmp-c)/2;

	}

	

	c=0;

	for(int i=k-1;i>=0;i--)

	{

		int tmp=temp2[i]+s[i]-'a'+c;

		if(tmp>=26)c=1;

		else c=0;

		

		a[i]=tmp-c*26+'a';

	} 

	 

	printf("%s",a);

	return 0;

}


Comments

Submit
0 Comments
More Questions

1660A - Vasya and Coins
1660E - Matrix and Shifts
1293B - JOE is on TV
1584A - Mathematical Addition
1660B - Vlad and Candies
1472C - Long Jumps
1293D - Aroma's Search
918A - Eleven
1237A - Balanced Rating Changes
1616A - Integer Diversity
1627B - Not Sitting
1663C - Pōja Verdon
1497A - Meximization
1633B - Minority
688B - Lovely Palindromes
66B - Petya and Countryside
1557B - Moamen and k-subarrays
540A - Combination Lock
1553C - Penalty
1474E - What Is It
1335B - Construct the String
1004B - Sonya and Exhibition
1397A - Juggling Letters
985C - Liebig's Barrels
115A - Party
746B - Decoding
1424G - Years
1663A - Who Tested
1073B - Vasya and Books
195B - After Training